import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import 'amfe-flexible/index.js' //rem转换插件
import './assets/css/normalize.css'
import NProgress from 'nprogress' //加载条
import 'nprogress/nprogress.css'


axios.defaults.baseURL = 'https://elm.cangdu.org/' //设置默认请求接口地址


import { Button, Card, Notify, Loading, Uploader, SubmitBar, Sticky, SwipeCell, Stepper, Skeleton, Toast, DropdownMenu, Checkbox, CheckboxGroup, RadioGroup, Radio, DropdownItem, Dialog, Overlay, Sidebar, TreeSelect, SidebarItem, Lazyload, Tab, Tabs, Swipe, Tag, Rate, SwipeItem, NavBar, Icon, IndexBar, IndexAnchor, Col, Row, Grid, GridItem, Image, Cell, Field, CellGroup, Tabbar, TabbarItem, List } from 'vant'

Vue.use(Button).use(Card).use(Loading).use(Uploader).use(SubmitBar).use(NavBar).use(Sticky).use(SwipeCell).use(Stepper).use(Skeleton).use(Toast).use(Notify).use(Checkbox).use(CheckboxGroup).use(RadioGroup).use(Radio).use(DropdownItem).use(DropdownMenu).use(Lazyload).use(Icon).use(IndexBar).use(IndexAnchor).use(Col).use(Row).use(Grid).use(GridItem).use(Image).use(Cell).use(Field).use(CellGroup).use(Tabbar).use(TabbarItem)
  .use(Swipe).use(SwipeItem).use(Overlay).use(Dialog).use(List).use(Tag).use(Rate).use(Tab).use(Tabs).use(Sidebar).use(SidebarItem).use(TreeSelect)
Vue.config.productionTip = false
Vue.prototype.$axios = axios //将axios放到vue原型方法上
axios.defaults.withCredentials = true; //允许传cookie


axios.interceptors.request.use(
  config => {
    // if (store.state.token) { // 判断是否存在token，如果存在的话，则每个http header都加上token
    //   config.headers.authorization = store.state.token  //请求头加上token
    // }
    NProgress.start();
    return config
  },
  err => {
    return Promise.reject(err)
  })

axios.interceptors.response.use(
  response => {
    //拦截响应，做统一处理 
    NProgress.done();
    return response
  },
  //接口错误状态处理，也就是说无响应时的处理
  error => {
    return Promise.reject(error.response.status) // 返回接口返回的错误信息
  })



new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
